//
//  LoginViewController.m
//  ZHIDOU
//
//  Created by 向礼 on 2018/12/25.
//  Copyright © 2018 向礼. All rights reserved.
//

#import "LoginViewController.h"
#import "LoginTextFiled.h"
#import "registerViewController.h"

@interface LoginViewController ()

@property (nonatomic ,strong)UIImageView *headImageView;

@property (nonatomic ,strong)LoginTextFiled *phoneTextField;

@property (nonatomic ,strong)LoginTextFiled *passwordTextField;

@property (nonatomic ,strong)UIButton *ForgetBtn;

@property (nonatomic ,strong)UIButton *loginBtn;

@property (nonatomic ,strong)UIView *lineView;

@property (nonatomic ,strong)UILabel *diSanFang;

@property (nonatomic ,strong)UIButton *weichatBtn;

@property (nonatomic ,strong)UIButton *QQBtn;
@end

@implementation LoginViewController
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.navigationController setNavigationBarHidden:NO animated:YES];
    [self setSubViews];
    [self creatRight];
}

#pragma mark - nav右边的导航栏
- (void)creatRight{
   //[self.navController setrightNavBtn:@"" andRightImage:@""];
    UIButton *myButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 50, 20)];
    [myButton setTitle:@"注册" forState:UIControlStateNormal];
    [myButton addTarget:self action:@selector(clickEvent) forControlEvents:UIControlEventTouchUpInside];
    [myButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [myButton.titleLabel setFont:[UIFont systemFontOfSize:14]];
    UIBarButtonItem *rightCunstomButtonView = [[UIBarButtonItem alloc] initWithCustomView:myButton];
    self.navigationItem.rightBarButtonItem = rightCunstomButtonView;
}

#pragma mark - UI
-(void)setSubViews{
    self.view.backgroundColor = [UIColor whiteColor];
    self.headImageView.frame = CGRectMake((ZD_screenWidth - 67 *ZD_defaultScale)/2, 40*ZD_defaultScale, 67*ZD_defaultScale, 67*ZD_defaultScale);
    [self.view addSubview:_headImageView];
    self.phoneTextField.frame = CGRectMake(15, self.headImageView.bottom + 53*ZD_defaultScale, ZD_screenWidth-30*ZD_defaultScale, 50*ZD_defaultScale);
    [self.view addSubview:self.phoneTextField];
    self.passwordTextField.frame = CGRectMake(15,  self.phoneTextField.bottom+20*ZD_defaultScale, ZD_screenWidth-30, 50);
    [self.view addSubview:self.passwordTextField];
    self.ForgetBtn.frame = CGRectMake(ZD_screenWidth-75, self.passwordTextField.bottom, 60, 34*ZD_defaultScale);
    [self.view addSubview:self.ForgetBtn];
    [self.view addSubview:self.loginBtn];
    [self.view addSubview:self.lineView];
    [self.view addSubview:self.diSanFang];
    [self.view addSubview:self.weichatBtn];
    [self.view addSubview:self.QQBtn];
}

#pragma mark - lazy
- (UIImageView *)headImageView{
    if (_headImageView == nil) {
        _headImageView = [[UIImageView alloc]init];
        _headImageView.backgroundColor = [UIColor blackColor];
    }
    return _headImageView;
}

-(LoginTextFiled *)phoneTextField{
    if (_phoneTextField == nil) {
        _phoneTextField = [[LoginTextFiled alloc]init];
        _phoneTextField.filedType = phoneType;
    }
    return _phoneTextField;
}

-(LoginTextFiled *)passwordTextField{
    if (_passwordTextField == nil) {
        _passwordTextField = [[LoginTextFiled alloc]init];
        _passwordTextField.leftImage = @"login_icon_lock";
        _passwordTextField.PlaceStr = @"请输入密码";
        _passwordTextField.filedType = passWordType;

    }
    return _passwordTextField;
}

- (UIButton *)ForgetBtn{
    if (_ForgetBtn == nil) {
        _ForgetBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_ForgetBtn setTitle:@"忘记密码" forState:UIControlStateNormal];
        [_ForgetBtn setTitleColor:UIColorFromRGB(0xFF663E) forState:UIControlStateNormal];
        _ForgetBtn.titleLabel.font = [UIFont systemFontOfSize:12];
    }
    return _ForgetBtn;
}

- (UIButton *)loginBtn{
    if (_loginBtn == nil) {
        _loginBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_loginBtn setTitle:@"登录" forState:UIControlStateNormal];
        [_loginBtn setBackgroundColor:UIColorFromRGB(0xCCCCCC)];
        [_loginBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _loginBtn.titleLabel.font = [UIFont systemFontOfSize:15];
        _loginBtn.frame = CGRectMake(15, _ForgetBtn.bottom +22*ZD_defaultScale, ZD_screenWidth-30, 50);
        _loginBtn.layer.cornerRadius = 25;
        _loginBtn.layer.masksToBounds = YES;
    }
    return _loginBtn;
}

-(UIView *)lineView{
    if (_lineView == nil) {
        _lineView = [[UIView alloc]initWithFrame:CGRectMake(15, ZD_screenHeight -self.bottomSafeAreaInsets-126, ZD_screenWidth-30, 1)];
        _lineView.backgroundColor = UIColorFromRGB(0xE6E6E6);
    }
    return _lineView;
}

-(UILabel *)diSanFang{
    if (_diSanFang == nil) {
        _diSanFang = [[UILabel alloc]init];
        _diSanFang.backgroundColor = [UIColor whiteColor];
        _diSanFang.text = @"第三方登录";
        _diSanFang.textColor = UIColorFromRGB(0x999999);
        _diSanFang.textAlignment = NSTextAlignmentCenter;
        _diSanFang.frame = CGRectMake(0, 0, 100, 30);
        _diSanFang.center = self.lineView.center;
        _diSanFang.font = [UIFont systemFontOfSize:14];
    }
    return _diSanFang;
}

- (UIButton *)weichatBtn{
    if (_weichatBtn == nil) {
        _weichatBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_weichatBtn setImage:[UIImage imageNamed:@"login_wechat"] forState:UIControlStateNormal];
        _weichatBtn.frame = CGRectMake((ZD_screenWidth - 120)/2, self.lineView.bottom+36, 40, 40);
    }
    return _weichatBtn;
}

- (UIButton *)QQBtn{
    if (_QQBtn == nil) {
        _QQBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_QQBtn setImage:[UIImage imageNamed:@"login_qq"] forState:UIControlStateNormal];
        _QQBtn.frame = CGRectMake(ZD_screenWidth/2 +20, self.lineView.bottom+36, 40, 40);
    }
    return _QQBtn;
}


- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [self.view endEditing:YES];
}

- (void)clickEvent{
    registerViewController *registerVC = [[registerViewController alloc]init];
    [self.navigationController pushViewController:registerVC animated:YES];
}

@end
